package role

import (
	"context"
	"time"

	"go-weixin/app/usercenter/api/internal/svc"
	"go-weixin/app/usercenter/api/internal/types"
	"go-weixin/app/usercenter/rpc/pb/proto/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleapiAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleapiAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleapiAddLogic {
	return &RoleapiAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleapiAddLogic) RoleapiAdd(req *types.RoleAddReq) (resp *types.RoleAddResp, err error) {
	ctx, canelFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer canelFunc()
	_, err = l.svcCtx.UserRpc.RoleAdd(ctx, &usercenter.RoleAddReq{
		Name:     req.Name,
		Weight:   req.Weight,
		ParentId: req.ParentId,
	})
	return
}
